count the occurrences of a character in a string